package com.zx._10_设计模式.行为型模式.责任链模式.demo2;

/**
 * 责任链--执行器(链表形式)
 *
 * @date: 2019年6月18日上午10:21:06
 */
public class ChianHandlerLinkedProcess {

    private ChianHandler firstHandler;

    public ChianHandlerLinkedProcess() {
        this.firstHandler = new Demo1ChianHandler();
        ChianHandler demo2 = new Demo2ChianHandler();
        firstHandler.nextChianHandler = demo2;

    }

    public boolean process() {
        ChianHandler handler = this.firstHandler;
        boolean result = true;

        while (handler != null) {
            if (handler.run()) {
                handler = handler.nextChianHandler;
            } else {
                result = false;
                break;
            }
        }
        return result;
    }

}
